Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pydantic V2 support #13

Closed
wants to merge 3 commits into from
Closed

Pydantic V2 support #13

wants to merge 3 commits into from

Conversation

ansenlong
Copy link

Added Pydantic V2 support

Added Pydantic V2 support
Copy link
Owner

@fcurella fcurella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Could you add some tests and run make lint to fix the linting issues?

@@ -169,6 +169,16 @@ def validate(cls, v: str) -> Self:
raise ValueError("invalid data-uri format")
return m

@classmethod
def __get_pydantic_json_schema__(cls, core_schema: Any, handler: Any) -> Any:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't core_schema have type Mapping[str, Any], as in pydantic_core?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added mapping Dict

tests/test_pydantic.py Outdated Show resolved Hide resolved
tests/test_pydantic.py Outdated Show resolved Hide resolved
== '{"content": "data:text/plain;charset=utf-8;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0'
'aGUgbGF6eSBkb2cu"}'
instance.__getattr__(func_json)()
== '{"content":"data:text/plain;charset=utf-8;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu"}'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we test both?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to test for this edge case

- Updated the test suite in 'tests/test_pydantic.py' to enhance compatibility with various Pydantic versions.
- Previously, the test suite attempted to access attributes 'model_dump_json' and 'model_dump' without exception handling, potentially causing test failures with specific Pydantic versions.
- In this commit, we've improved compatibility by handling AttributeError exceptions and determining the appropriate functions ('json' and 'dict') to use based on the available Pydantic version.
@ansenlong ansenlong closed this by deleting the head repository Sep 27, 2023
@regoawt regoawt mentioned this pull request Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants